package xiancheng.deadlock;

/**
 * @author Mr.ma
 * @since 2022/11/1 21:12
 **/
public class Test10 {
    public static void main(String[] args) {
        Printer printer = new Printer();
        Thread thread01 = new Thread(printer);
        Thread thread02 = new Thread(printer);
        thread01.setName("小明");
        thread02.setName("小刚");
        thread01.start();
        thread02.start();
    }
}
class Printer implements Runnable{
    public static Object board = new Object();
    public static Object brush = new Object();
    @Override
    public void run() {
        synchronized (Printer.board){
            System.out.println(Thread.currentThread().getName() + "拿到画板");
            synchronized (Printer.brush){
                System.out.println(Thread.currentThread().getName() + "拿到画笔");
                synchronized (Printer.board){
                    System.out.println(Thread.currentThread().getName() + "再次拿到画板");
                }
            }
        }
    }
}
